package adv5;


import adv4.Cal;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
import java.util.SimpleTimeZone;

/**
 * @author oldliu
 * @since 1.0
 */
public class NextBirthday {
    public static void main(String[] args) {
        System.out.println("输入生日：");
        String str = new Scanner(System.in).next();
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        c.set(Calendar.HOUR, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        Date now = c.getTime();
        System.out.println(now);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        df.setLenient(false);
        Date b = null;//下次生日
        for (int i = 0; i < 8; i++,year++) {
            try {
                String bstr = year + "-" + str;//2023-5-14
                b = df.parse(bstr);
                System.out.println(b);
                if (b.compareTo(now) >= 0) {
                    break;
                }
            } catch (Exception e) {

            }

        }
        if(b==null){
            System.out.println("输入错误");
            return;
        }
        System.out.println("你下次生日的时间是："+b);

        int days= (int) ((b.getTime()-now.getTime())/1000/3600/24);
        System.out.println(days);
    }
}
